package com.cfw.collection;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.swing.tree.DefaultMutableTreeNode;

import org.w3c.dom.Node;

import com.cfw.collection.TreeSearch.AbstractNavigateCallback;
import com.cfw.collection.TreeSearch.AbstractSourceCallback;

public class TreeSearchBaseCallback {
	
	public static class MutableTreeNodeSource extends AbstractSourceCallback {
		public MutableTreeNodeSource(Object data) { super(data); }

		@Override
		public boolean isLeaf(Object node) { return ((DefaultMutableTreeNode)node).isLeaf(); }

		@Override
		public Object getNextSibling(Object node) { return ((DefaultMutableTreeNode)node).getNextSibling(); }

		@Override
		public Object getUserObject(Object node) { return ((DefaultMutableTreeNode)node).getUserObject(); }

		@Override
		public Object getFirstChild(Object node) { return ((DefaultMutableTreeNode)node).getFirstChild(); }
	}

	public static class MapTreeSource extends AbstractSourceCallback {
		public MapTreeSource(Object data) { super(data); }

		@Override
		public boolean isLeaf(Object node) { return ((MapTree)node).isLeaf(); }

		@Override
		public Object getNextSibling(Object node) { return ((MapTree)node).getNextSibling(); }

		@Override
		public Object getUserObject(Object node) { return ((MapTree)node).getUserObject(); }

		@Override
		public Object getFirstChild(Object node) { return ((MapTree)node).getFirstChild(); }
	}
	
	public static class XmlSource extends AbstractSourceCallback {
		public XmlSource(Object data) { super(data); }

		@Override
		public boolean isLeaf(Object node) { return !((Node)node).hasChildNodes(); }

		@Override
		public Object getNextSibling(Object node) { return ((Node)node).getNextSibling(); }

		@Override
		public Object getUserObject(Object node) { return node; }

		@Override
		public Object getFirstChild(Object node) { return ((Node)node).getFirstChild(); }
	}

}
